using NICWebApi.Extensions.Http.Models;

/// <summary>
/// HTTP上下文工具接口
/// </summary>
public interface IHttpContextUtils
{
    /// <summary>
    /// 获取客户端IP地址
    /// </summary>
    /// <returns>IP地址和提供者</returns>
    (string IpAddress, string Provider) GetClientIpAddress();

    /// <summary>
    /// 获取Web请求信息
    /// </summary>
    /// <param name="includeHeaders">是否包含请求头</param>
    /// <returns>HTTP上下文信息</returns>
    HttpContextInfo GetRequestInfo(bool includeHeaders = true);

    /// <summary>
    /// 解析用户代理信息
    /// </summary>
    /// <param name="userAgent">用户代理字符串</param>
    /// <returns>用户代理信息</returns>
    UserAgentInfo ParseUserAgent(string userAgent);

    /// <summary>
    /// 获取客户端浏览器信息
    /// </summary>
    /// <returns>浏览器信息</returns>
    string GetUserAgent();

    /// <summary>
    /// 获取当前请求的URL
    /// </summary>
    /// <param name="includeQueryString">是否包含查询字符串</param>
    /// <returns>完整URL</returns>
    string GetRequestUrl(bool includeQueryString = true);

    /// <summary>
    /// 获取请求头值
    /// </summary>
    /// <param name="headerName">请求头名称</param>
    /// <returns>请求头值</returns>
    string GetHeaderValue(string headerName);

    /// <summary>
    /// 获取请求头集合
    /// </summary>
    /// <param name="headerNames">请求头名称列表</param>
    /// <returns>请求头集合</returns>
    IDictionary<string, string> GetHeaderValues(IEnumerable<string> headerNames);

    /// <summary>
    /// 获取请求来源URL
    /// </summary>
    /// <returns>来源URL</returns>
    string GetReferrer();

    /// <summary>
    /// 获取请求的路由值
    /// </summary>
    /// <param name="routeValueKey">路由值键</param>
    /// <returns>路由值</returns>
    string GetRouteValue(string routeValueKey);

    /// <summary>
    /// 判断请求是否为AJAX请求
    /// </summary>
    /// <returns>是否为AJAX请求</returns>
    bool IsAjaxRequest();

    /// <summary>
    /// 判断请求是否为移动设备
    /// </summary>
    /// <returns>是否为移动设备</returns>
    bool IsMobileDevice();

    /// <summary>
    /// 获取请求的内容类型
    /// </summary>
    /// <returns>内容类型</returns>
    string GetContentType();

    /// <summary>
    /// 登录到Swagger
    /// </summary>
    void SignInToSwagger(string accessToken);

    /// <summary>
    /// 登出Swagger
    /// </summary>
    void SignOutToSwagger();

    /// <summary>
    /// 获取 Action 特性
    /// </summary>
    /// <typeparam name="TAttribute"></typeparam>
    /// <returns></returns>
    TAttribute GetMetadata<TAttribute>() where TAttribute : class;

    /// <summary>
    /// 获取控制器方法描述
    /// </summary>
    /// <returns></returns>
    ControllerActionDescriptor GetControllerActionDescriptor();

    /// <summary>
    /// 获取路由数据
    /// </summary>
    /// <returns></returns>
    RouteData GetRouteData();

    /// <summary>
    /// 设置响应头中的访问令牌和刷新令牌
    /// </summary>
    /// <param name="httpContext"></param>
    /// <param name="accessToken"></param>
    /// <param name="refreshToken"></param>
    void SetTokensOfResponseHeaders(string accessToken, string refreshToken = null);

    /// <summary>
    /// 读取请求体内容
    /// </summary>
    /// <returns></returns>
    Task<string> ReadBodyContentAsync();
}